home *** CD-ROM | disk | FTP | other *** search
/ Gamers Delight 2 / Gamers Delight 2.iso / Aminet / game / role / Ang261Lib.lha / src / magic.c < prev    next >
C/C++ Source or Header  |  1994-10-22  |  10KB  |  365 lines

  1. /*
  2.  * magic.c: code for mage spells 
  3.  *
  4.  * Copyright (c) 1989 James E. Wilson, Robert A. Koeneke 
  5.  *
  6.  * This software may be copied and distributed for educational, research, and
  7.  * not for profit purposes provided that this copyright and statement are
  8.  * included in all such copies. 
  9.  */
  10.  
  11. #include "constant.h"
  12. #include "config.h"
  13. #include "types.h"
  14. #include "externs.h"
  15.  
  16. /* Lets do all prototypes correctly.... -CWS */
  17. #ifndef NO_LINT_ARGS
  18. int door_creation();
  19. int detect_magic();
  20. int stair_creation();
  21. #endif
  22.  
  23. /* Throw a magic spell                    -RAK-     */
  24. void 
  25. cast()
  26. {
  27.     int                    i, j, item_val, dir;
  28.     int                    choice, chance, result;
  29.     register struct flags *f_ptr;
  30.     register struct misc  *p_ptr;
  31.     register spell_type   *m_ptr;
  32.  
  33.     free_turn_flag = TRUE;
  34.     if (py.flags.blind > 0)
  35.     msg_print("You can't see to read your spell book!");
  36.     else if (no_light())
  37.     msg_print("You have no light to read by.");
  38.     else if (py.flags.confused > 0)
  39.     msg_print("You are too confused.");
  40.     else if (class[py.misc.pclass].spell != MAGE)
  41.     msg_print("You can't cast spells!");
  42.     else if (!find_range(TV_MAGIC_BOOK, TV_NEVER, &i, &j))
  43.     msg_print("But you are not carrying any spell-books!");
  44.     else if (get_item(&item_val, "Use which spell-book?", i, j, 0)) {
  45.     result = cast_spell("Cast which spell?", item_val, &choice, &chance);
  46.     if (py.flags.stun > 50)
  47.         chance += 25;
  48.     else if (py.flags.stun > 0)
  49.         chance += 15;
  50.     if (result < 0)
  51.         msg_print("You don't know any spells in that book.");
  52.     else if (result > 0) {
  53.         m_ptr = &magic_spell[py.misc.pclass - 1][choice];
  54.         free_turn_flag = FALSE;
  55.  
  56.         if (randint(100) <= chance)    /* changed -CFT */
  57.         msg_print("You failed to get the spell off!");
  58.         else {
  59.         chance = py.misc.lev/
  60.             (py.misc.pclass==1 ? 2 : (py.misc.pclass==4 ? 4 : 5))
  61.                         + stat_adj(A_INT); /* does missile spell do line? -CFT */
  62.         
  63.         /* Spells.  */
  64.         switch (choice + 1) {
  65.           case 1:
  66.             if (get_dir(NULL, &dir))
  67.             if (randint(100) < (chance-10))
  68.                 line_spell(GF_MAGIC_MISSILE, dir, char_row, char_col,
  69.                        damroll(3 + ((py.misc.lev - 1) / 5), 4) );
  70.             else
  71.                 fire_bolt(GF_MAGIC_MISSILE, dir, char_row, char_col,
  72.                       damroll(3 + ((py.misc.lev - 1) / 5), 4) );
  73.             break;
  74.           case 2:
  75.             (void)detect_monsters();
  76.             break;
  77.           case 3:
  78.             teleport(10);
  79.             break;
  80.           case 4:
  81.             (void)light_area(char_row, char_col,
  82.                damroll(2, (py.misc.lev / 2)), (py.misc.lev / 10) + 1);
  83.             break;
  84.           case 5:       /* treasure detection */
  85.             (void)detect_treasure();
  86.             break;
  87.           case 6:
  88.             (void)hp_player(damroll(4, 4));
  89.             if (py.flags.cut > 0) {
  90.             py.flags.cut -= 15;
  91.             if (py.flags.cut < 0)
  92.                 py.flags.cut = 0;
  93.             msg_print("Your wounds heal.");
  94.             }
  95.             break;
  96.           case 7:       /* object detection */
  97.             (void)detect_object();
  98.             break;
  99.           case 8:
  100.             (void)detect_sdoor();
  101.             (void)detect_trap();
  102.             break;
  103.           case 9:
  104.             if (get_dir(NULL, &dir))
  105.             fire_ball(GF_POISON_GAS, dir, char_row, char_col,
  106.                   10 + (py.misc.lev / 2), 2);
  107.             break;
  108.           case 10:
  109.             if (get_dir(NULL, &dir))
  110.             (void)confuse_monster(dir, char_row, char_col, py.misc.lev);
  111.             break;
  112.           case 11:
  113.             if (get_dir(NULL, &dir))
  114.             if (randint(100) < (chance-10))
  115.                 line_spell(GF_LIGHTNING, dir, char_row, char_col,
  116.                        damroll(3+((py.misc.lev-5)/4),8));
  117.             else
  118.                 fire_bolt(GF_LIGHTNING, dir, char_row, char_col,
  119.                       damroll(3+((py.misc.lev-5)/4),8));
  120.             break;
  121.           case 12:
  122.             (void)td_destroy();
  123.             break;
  124.           case 13:
  125.             if (get_dir(NULL, &dir))
  126.             (void)sleep_monster(dir, char_row, char_col);
  127.             break;
  128.           case 14:
  129.             (void)cure_poison();
  130.             break;
  131.           case 15:
  132.             teleport((int)(py.misc.lev * 5));
  133.             break;
  134.           case 16:
  135.             if (get_dir(NULL, &dir)) {
  136.             msg_print("A line of blue shimmering light appears.");
  137.             light_line(dir, char_row, char_col);
  138.             }
  139.             break;
  140.           case 17:
  141.             if (get_dir(NULL, &dir))
  142.             if (randint(100) < (chance-10))
  143.                 line_spell(GF_FROST, dir, char_row, char_col,
  144.                        damroll(5+((py.misc.lev-5)/4),8));
  145.             else
  146.                 fire_bolt(GF_FROST, dir, char_row, char_col,
  147.                       damroll(5+((py.misc.lev-5)/4),8));
  148.             break;
  149.           case 18:
  150.             if (get_dir(NULL, &dir))
  151.             (void)wall_to_mud(dir, char_row, char_col);
  152.             break;
  153.           case 19:
  154.             create_food();
  155.             break;
  156.           case 20:
  157.             (void)recharge(5);
  158.             break;
  159.           case 21:
  160.             (void)sleep_monsters1(char_row, char_col);
  161.             break;
  162.           case 22:
  163.             if (get_dir(NULL, &dir))
  164.             (void)poly_monster(dir, char_row, char_col);
  165.             break;
  166.           case 23:
  167.             (void)ident_spell();
  168.             break;
  169.           case 24:
  170.             (void)sleep_monsters2();
  171.             break;
  172.           case 25:
  173.             if (get_dir(NULL, &dir))
  174.             if (randint(100) < chance)
  175.                 line_spell(GF_FIRE, dir, char_row, char_col,
  176.                        damroll(8+((py.misc.lev-5)/4),8));
  177.             else
  178.                 fire_bolt(GF_FIRE, dir, char_row, char_col,
  179.                       damroll(8+((py.misc.lev-5)/4),8));
  180.             break;
  181.           case 26:
  182.             if (get_dir(NULL, &dir))
  183.             (void)speed_monster(dir, char_row, char_col, -1);
  184.             break;
  185.           case 27:
  186.             if (get_dir(NULL, &dir))
  187.             fire_ball(GF_FROST, dir, char_row, char_col,
  188.                   30 + (py.misc.lev), 2);
  189.             break;
  190.           case 28:
  191.             (void)recharge(40);
  192.             break;
  193.           case 29:
  194.             if (get_dir(NULL, &dir))
  195.             (void)teleport_monster(dir, char_row, char_col);
  196.             break;
  197.           case 30:
  198.             f_ptr = &py.flags;
  199.             if (f_ptr->fast <= 0)
  200.             f_ptr->fast += randint(20) + py.misc.lev;
  201.             else
  202.             f_ptr->fast += randint(5);
  203.             break;
  204.           case 31:
  205.             if (get_dir(NULL, &dir))
  206.             fire_ball(GF_FIRE, dir, char_row, char_col
  207.                   , 55 + (py.misc.lev), 2);
  208.             break;
  209.           case 32:
  210.             destroy_area(char_row, char_col);
  211.             break;
  212.           case 33:
  213.             (void)genocide(TRUE);
  214.             break;
  215.           case 34:       /* door creation */
  216.             (void)door_creation();
  217.             break;
  218.           case 35:       /* Stair creation */
  219.             (void)stair_creation();
  220.             break;
  221.           case 36:       /* Teleport level */
  222.             (void)tele_level();
  223.             break;
  224.           case 37:       /* Earthquake */
  225.             earthquake();
  226.             break;
  227.           case 38:       /* Word of Recall */
  228.             if (py.flags.word_recall == 0) {
  229.             py.flags.word_recall = 15 + randint(20);
  230.             msg_print("The air about you becomes charged...");
  231.             } else {
  232.             py.flags.word_recall = 0;
  233.             msg_print("A tension leaves the air around you...");
  234.             }
  235.             break;
  236.           case 39:       /* Acid Bolt */
  237.             if (get_dir(NULL, &dir))
  238.             if (randint(100) < (chance-5))
  239.                 line_spell(GF_ACID, dir, char_row, char_col,
  240.                        damroll(6+((py.misc.lev-5)/4), 8));
  241.             else
  242.                 fire_bolt(GF_ACID, dir, char_row, char_col,
  243.                       damroll(6+((py.misc.lev-5)/4), 8));
  244.             break;
  245.           case 40:       /* Cloud kill */
  246.             if (get_dir(NULL, &dir))
  247.             fire_ball(GF_POISON_GAS, dir, char_row, char_col,
  248.                   20 + (py.misc.lev / 2), 3);
  249.             break;
  250.           case 41:       /* Acid Ball */
  251.             if (get_dir(NULL, &dir))
  252.             fire_ball(GF_ACID, dir, char_row, char_col,
  253.                   40 + (py.misc.lev), 2);
  254.             break;
  255.           case 42:       /* Ice Storm */
  256.             if (get_dir(NULL, &dir))
  257.             fire_ball(GF_FROST, dir, char_row, char_col,
  258.                   70 + (py.misc.lev), 3);
  259.             break;
  260.           case 43:       /* Meteor Swarm */
  261.             if (get_dir(NULL, &dir))
  262.             fire_ball(GF_METEOR, dir, char_row, char_col,
  263.                   65 + (py.misc.lev), 3);
  264.             break;
  265.           case 44:       /* Hellfire */
  266.             if (get_dir(NULL, &dir))
  267.             fire_ball(GF_HOLY_ORB, dir, char_row, char_col, 300, 2);
  268.             break;
  269.           case 45:       /* Detect Evil */
  270.             (void)detect_evil();
  271.             break;
  272.           case 46:       /* Detect Enchantment */
  273.             (void)detect_magic();
  274.             break;
  275.           case 47:
  276.             recharge(100);
  277.             break;
  278.           case 48:
  279.             (void)genocide(TRUE);
  280.             break;
  281.           case 49:
  282.             (void)mass_genocide(TRUE);
  283.             break;
  284.           case 50:
  285.             py.flags.resist_heat += randint(20) + 20;
  286.             break;
  287.           case 51:
  288.             py.flags.resist_cold += randint(20) + 20;
  289.             break;
  290.           case 52:
  291.             py.flags.resist_acid += randint(20) + 20;
  292.             break;
  293.           case 53:
  294.             py.flags.resist_poison += randint(20) + 20;
  295.             break;
  296.           case 54:
  297.             py.flags.resist_heat += randint(20) + 20;
  298.             py.flags.resist_cold += randint(20) + 20;
  299.             py.flags.resist_light += randint(20) + 20;
  300.             py.flags.resist_poison += randint(20) + 20;
  301.             py.flags.resist_acid += randint(20) + 20;
  302.             break;
  303.           case 55:
  304.             py.flags.hero += randint(25) + 25;
  305.             break;
  306.           case 56:
  307.             py.flags.shield += randint(20) + 30;
  308.             calc_bonuses();
  309.             prt_pac();
  310.             calc_mana(A_INT);
  311.             msg_print("A mystic shield forms around your body!");
  312.             break;
  313.           case 57:
  314.             py.flags.shero += randint(25) + 25;
  315.             break;
  316.           case 58:
  317.             if (py.flags.fast <= 0)
  318.             py.flags.fast += randint(30) + 30 + py.misc.lev;
  319.             else
  320.             py.flags.fast += randint(5);
  321.             break;
  322.           case 59:
  323.             py.flags.invuln += randint(8) + 8;
  324.             break;
  325.           default:
  326.             break;
  327.         }
  328.         /* End of spells.                     */
  329.         if (!free_turn_flag) {
  330.             p_ptr = &py.misc;
  331.             if (choice < 32) {
  332.             if ((spell_worked & (1L << choice)) == 0) {
  333.                 p_ptr->exp += m_ptr->sexp << 2;
  334.                 spell_worked |= (1L << choice);
  335.                 prt_experience();
  336.             }
  337.             } else {
  338.             if ((spell_worked2 & (1L << (choice - 32))) == 0) {
  339.                 p_ptr->exp += m_ptr->sexp << 2;
  340.                 spell_worked2 |= (1L << (choice - 32));
  341.                 prt_experience();
  342.             }
  343.             }
  344.         }
  345.         }
  346.         p_ptr = &py.misc;
  347.         if (!free_turn_flag) {
  348.         if (m_ptr->smana > p_ptr->cmana) {
  349.             msg_print("You faint from the effort!");
  350.             py.flags.paralysis =
  351.             randint((int)(5 * (m_ptr->smana - p_ptr->cmana)));
  352.             p_ptr->cmana = 0;
  353.             p_ptr->cmana_frac = 0;
  354.             if (randint(3) == 1) {
  355.             msg_print("You have damaged your health!");
  356.             (void)dec_stat(A_CON);
  357.             }
  358.         } else
  359.             p_ptr->cmana -= m_ptr->smana;
  360.         prt_cmana();
  361.         }
  362.     }
  363.     }
  364. }
  365.